#coding:utf-8
from django.http import HttpResponse
from lovewith.api.weixin.weixin import Weixin
from django.views.decorators.csrf import csrf_exempt


@csrf_exempt
def receive_msg(request):
    signature = request.GET.get('signature')
    timestamp = request.GET.get('timestamp')
    nonce = request.GET.get('nonce')
    echostr = request.GET.get('echostr')
    xml_body = request.body

    result = '@南瓜小米粥'

    if signature and timestamp and nonce and echostr:
        result = Weixin().validate(signature, timestamp, nonce, echostr)
    if xml_body:
        result = Weixin().get_message(xml_body)

    return HttpResponse(result)